% fname: routing_oddeven__sel_random__topology_8x8__.m
% ./noxim -routing oddeven -sel random -dimx 8 -dimy 8  -sim 10000 -warmup 2000 -size 8 8 -buffer 4 -hs 6 0.2 -hs 7 0.2 -hs 14 0.2 -hs 15 0.2 

function [max_pir, max_throughput, min_delay] = routing_oddeven__sel_random__topology_8x8__(symbol)

data = [
%             pir      avg_delay     throughput      max_delay       rpackets         rflits
           0.0015        20.2688      0.0125826             83            744           5939
           0.0015        20.8599      0.0134758             94            835           6684
           0.0015        19.9127      0.0135826            107            802           6411
           0.0015        20.1959      0.0137127            117            781           6253
           0.0015        18.8293      0.0128233             64            744           5950
           0.0015        20.4484      0.0121131            101            765           6105
           0.0015         20.515      0.0129513             91            765           6113
           0.0015        20.2494      0.0126855             99            786           6292
           0.0015        20.5348      0.0136336            100            791           6326
           0.0015        18.8468      0.0134116             88            777           6223
           0.0015         19.647      0.0144167             84            779           6228
           0.0015         20.603      0.0135042            120            811           6482
           0.0015        20.9123      0.0136434            149            832           6658
           0.0015        21.4406      0.0132818             92            783           6269
           0.0015        19.7573       0.013569             80            787           6296
           0.0015         19.869      0.0128966             96            748           5984
           0.0015        20.0732      0.0134201             82            820           6549
           0.0015         20.552      0.0128453             86            759           6063
           0.0015        20.4132      0.0128771            121            760           6078
           0.0015        19.5138      0.0133289             99            759           6078
           0.0017        20.6311      0.0139104            111            835           6677
           0.0017         22.669      0.0136653            123            846           6778
           0.0017        19.4425      0.0132238             65            818           6559
           0.0017        22.7373      0.0152839            104            902           7214
           0.0017        21.5167      0.0135879            116            869           6957
           0.0017        23.1795      0.0150218             98            947           7571
           0.0017         22.164       0.014819            110            860           6876
           0.0017        21.2013      0.0142778            103            899           7196
           0.0017        21.3716      0.0142021            115            853           6817
           0.0017        19.4514      0.0130292             85            782           6254
           0.0017        21.6843      0.0145229            113            871           6971
           0.0017        21.9309       0.014709            133            897           7178
           0.0017        22.0536      0.0151886             88            896           7169
           0.0017        21.5998      0.0142131            112            867           6936
           0.0017        24.0227      0.0156992            150            927           7410
           0.0017        21.7945      0.0146815            106            910           7282
           0.0017         21.245      0.0137013             91            808           6467
           0.0017        20.0045      0.0144426            133            882           7048
           0.0017        21.3709      0.0138361            105            844           6752
           0.0017        21.4774      0.0147083            112            840           6707
           0.0019        22.7261      0.0166272            116            964           7715
           0.0019          23.62      0.0153226            129            950           7600
           0.0019        23.9391      0.0146131            168            919           7365
           0.0019        22.9439      0.0160927            149            998           7982
           0.0019        24.9592       0.016373            183           1030           8252
           0.0019        23.7472      0.0155635            124            981           7844
           0.0019        23.9883      0.0147363            203            942           7545
           0.0019        24.1218      0.0153508            137            952           7614
           0.0019        23.2026      0.0164667            108            987           7904
           0.0019        21.8006      0.0151371            130            938           7508
           0.0019         24.601      0.0160377            141           1010           8083
           0.0019        23.3152      0.0162581             98           1009           8064
           0.0019        22.7156      0.0157798            132            995           7953
           0.0019         23.151       0.015002            116            960           7681
           0.0019        21.8912      0.0154771            124            928           7429
           0.0019        22.8184       0.015631            148            969           7753
           0.0019        22.3323      0.0148433            124            936           7481
           0.0019        22.9058      0.0145363            168            902           7210
           0.0019        23.8908      0.0158206            208            980           7847
           0.0019        23.2051      0.0163508            158           1014           8110
           0.0021        25.8011      0.0173427            168           1076           8602
           0.0021        24.4318      0.0179201            149           1093           8745
           0.0021        26.7686      0.0171351            173           1063           8499
           0.0021        26.4133      0.0161996            151           1004           8035
           0.0021         24.774      0.0168125            180           1075           8608
           0.0021        29.8033      0.0174325            397           1098           8786
           0.0021        24.1285      0.0171573            141           1066           8510
           0.0021        24.0818      0.0170734            158           1076           8605
           0.0021        25.8185       0.018678            192           1102           8816
           0.0021        23.8977      0.0174611            138           1066           8521
           0.0021        24.1998      0.0175081            160           1086           8684
           0.0021        31.7061      0.0184201            430           1123           8989
           0.0021        24.3298      0.0185738            121           1131           9064
           0.0021        22.6549       0.017252            144           1052           8419
           0.0021        26.1747       0.017994            131           1116           8925
           0.0021        27.1687        0.01825            141           1132           9052
           0.0021        26.9134      0.0174899            183           1085           8675
           0.0021        26.1757      0.0172705            184           1053           8428
           0.0021        24.0392      0.0164536            163           1020           8161
           0.0021        29.1322      0.0176843            227           1044           8347
           0.0023        29.1133      0.0197266            224           1262          10100
           0.0023        23.6467      0.0185298            171           1169           9339
           0.0023        33.6505       0.019918            251           1216           9720
           0.0023        26.6237      0.0190101            128           1180           9429
           0.0023        26.0401      0.0189315            110           1173           9390
           0.0023         28.537          0.018            184           1134           9072
           0.0023        27.7042      0.0191429            194           1207           9648
           0.0023        28.6524      0.0192262            240           1211           9690
           0.0023        34.6736      0.0190079            397           1198           9580
           0.0023        27.6942       0.018994            273           1197           9573
           0.0023        31.2384      0.0188105            223           1204           9631
           0.0023        27.3668        0.01875            132           1164           9300
           0.0023        25.3076      0.0183036            150           1154           9225
           0.0023        28.9527      0.0187111            191           1141           9131
           0.0023        31.1374      0.0184336            300           1179           9438
           0.0023        30.4739       0.019131            371           1205           9642
           0.0023         25.989      0.0184219            132           1180           9432
           0.0023        26.0599      0.0179883            208           1152           9210
           0.0023        30.5297      0.0193299            157           1178           9433
           0.0023        31.0904       0.018256            257           1150           9201
           0.0025        30.6022      0.0202083            258           1272          10185
           0.0025        32.6025       0.020869            233           1293          10351
           0.0025        30.7273      0.0197601            344           1225           9801
           0.0025        35.8165      0.0213427            563           1324          10586
           0.0025        42.1958      0.0212684            411           1297          10379
           0.0025        35.3156      0.0212813            352           1277          10215
           0.0025        37.7293      0.0219792            285           1319          10550
           0.0025        30.6469      0.0201109            249           1246           9975
           0.0025         30.647      0.0196055            191           1255          10038
           0.0025        32.9569      0.0202222            319           1275          10192
           0.0025        30.0316      0.0209133            309           1297          10373
           0.0025        33.7097      0.0194902            237           1247           9979
           0.0025        30.8367      0.0201953            168           1292          10340
           0.0025        30.9235       0.020121            268           1268          10141
           0.0025        35.2591      0.0205833            200           1297          10374
           0.0025        32.4486      0.0205476            312           1295          10356
           0.0025        30.7011      0.0199766            201           1278          10228
           0.0025        29.5356      0.0188535            178           1208           9653
           0.0025        33.7666      0.0207578            275           1328          10628
           0.0025        38.6345      0.0207163            562           1305          10441
           0.0027        32.9783      0.0208809            314           1337          10691
           0.0027        35.6758      0.0216094            358           1382          11064
           0.0027        35.7472      0.0217782            231           1349          10802
           0.0027        53.5354      0.0225195            709           1442          11530
           0.0027        46.1148      0.0220352            722           1411          11282
           0.0027        42.8849      0.0225887            540           1399          11204
           0.0027        43.6105      0.0220547            338           1412          11292
           0.0027        36.7939      0.0209238            256           1339          10713
           0.0027         37.401      0.0217871            228           1394          11155
           0.0027         36.669      0.0229078            287           1399          11179
           0.0027        40.6858       0.022248            275           1378          11035
           0.0027        43.7044      0.0227029            387           1387          11079
           0.0027        44.9902       0.022631            484           1427          11406
           0.0027        37.7336      0.0214648            259           1374          10990
           0.0027        44.2996      0.0226434            457           1382          11050
           0.0027        33.7775      0.0217734            237           1393          11148
           0.0027         39.436      0.0218194            534           1374          10997
           0.0027        42.2519      0.0224395            519           1437          11489
           0.0027         36.131      0.0219012            521           1359          10863
           0.0027        42.8107      0.0222793            385           1426          11407
           0.0029         83.181      0.0235198           1670           1481          11854
           0.0029        47.2869      0.0225352            560           1443          11538
           0.0029        66.2638      0.0234881           1073           1482          11838
           0.0029        54.1759      0.0233516            470           1495          11956
           0.0029        55.3682      0.0252581            467           1567          12528
           0.0029        43.8394      0.0233613            294           1494          11961
           0.0029        38.8552      0.0232148            313           1485          11886
           0.0029        59.8123      0.0228633            629           1465          11706
           0.0029        51.6662      0.0239206            342           1507          12056
           0.0029        64.3347      0.0237363            814           1518          12153
           0.0029        59.0126      0.0235254           1025           1506          12045
           0.0029        50.0345      0.0243591            570           1535          12277
           0.0029        47.0543      0.0229961            417           1472          11774
           0.0029        48.9747      0.0228613            362           1462          11705
           0.0029         38.814      0.0220703            381           1414          11300
           0.0029        50.6247      0.0233047            494           1492          11932
           0.0029        49.3327      0.0238413            351           1503          12016
           0.0029        47.3128      0.0228281            440           1461          11688
           0.0029        70.3613      0.0244775           1262           1492          11945
           0.0029        56.4127      0.0229464            535           1444          11565
           0.0031        126.601      0.0259746           1544           1664          13299
           0.0031        68.0626      0.0245972            877           1549          12397
           0.0031        68.5919      0.0242266           1053           1551          12404
           0.0031        76.8025      0.0254663            595           1605          12835
           0.0031        67.7077      0.0246528           1421           1553          12425
           0.0031        96.6211      0.0258984            875           1660          13260
           0.0031         90.581      0.0257599           1809           1623          12983
           0.0031        72.5769       0.024459            876           1567          12523
           0.0031        94.2486      0.0268609           1232           1665          13323
           0.0031        67.4282      0.0245879           1105           1574          12589
           0.0031        53.4605      0.0249306            510           1570          12565
           0.0031        48.4623      0.0246992            377           1579          12646
           0.0031        102.604      0.0250357           1179           1577          12618
           0.0031        58.6768      0.0250992            533           1581          12650
           0.0031        55.4347      0.0244414            725           1562          12514
           0.0031        89.6051      0.0255099           1010           1608          12857
           0.0031        77.9743      0.0249023            764           1594          12750
           0.0031        59.2738      0.0249802            510           1574          12590
           0.0031        58.9548      0.0241621            902           1548          12371
           0.0031        60.8289      0.0247285            513           1584          12661
           0.0033        111.819      0.0259141           1416           1658          13268
           0.0033        122.512      0.0263125           1458           1684          13472
           0.0033        315.242      0.0256855           5126           1643          13151
           0.0033        212.298       0.026332           2548           1686          13482
           0.0033        157.175      0.0259577           2154           1609          12875
           0.0033        116.189      0.0264121           1459           1692          13523
           0.0033         188.74      0.0265762           3043           1701          13607
           0.0033        196.415      0.0264473           2268           1693          13541
           0.0033        113.977      0.0265357           1222           1673          13374
           0.0033        105.169      0.0263477           2381           1686          13490
           0.0033        87.2826      0.0251563           1055           1610          12880
           0.0033        323.946      0.0264722           4191           1666          13342
           0.0033         91.629      0.0259902            914           1663          13307
           0.0033        83.9803      0.0253887           1018           1624          12999
           0.0033        89.7866      0.0257187           1249           1645          13168
           0.0033        155.626      0.0268631           2559           1691          13539
           0.0033        187.878      0.0267227           2674           1711          13682
           0.0033        83.0846      0.0254883           1000           1631          13050
           0.0033        295.666      0.0269464           5342           1698          13581
           0.0033        155.523      0.0263867           1173           1687          13510
];

rows = size(data, 1);
cols = size(data, 2);

data_delay = [];
for i = 1:rows/20,
   ifirst = (i - 1) * 20 + 1;
   ilast  = ifirst + 20 - 1;
   tmp = data(ifirst:ilast, cols-5+1);
   avg = mean(tmp);
   [h sig ci] = ttest(tmp, 0.1);
   ci = (ci(2)-ci(1))/2;
   data_delay = [data_delay; data(ifirst, 1:cols-5), avg ci];
end

figure(1);
hold on;
plot(data_delay(:,1), data_delay(:,2), symbol);

data_throughput = [];
for i = 1:rows/20,
   ifirst = (i - 1) * 20 + 1;
   ilast  = ifirst + 20 - 1;
   tmp = data(ifirst:ilast, cols-5+2);
   avg = mean(tmp);
   [h sig ci] = ttest(tmp, 0.1);
   ci = (ci(2)-ci(1))/2;
   data_throughput = [data_throughput; data(ifirst, 1:cols-5), avg ci];
end

figure(2);
hold on;
plot(data_throughput(:,1), data_throughput(:,2), symbol);

data_maxdelay = [];
for i = 1:rows/20,
   ifirst = (i - 1) * 20 + 1;
   ilast  = ifirst + 20 - 1;
   tmp = data(ifirst:ilast, cols-5+3);
   avg = mean(tmp);
   [h sig ci] = ttest(tmp, 0.1);
   ci = (ci(2)-ci(1))/2;
   data_maxdelay = [data_maxdelay; data(ifirst, 1:cols-5), avg ci];
end

figure(3);
hold on;
plot(data_maxdelay(:,1), data_maxdelay(:,2), symbol);


%-------- Saturation Analysis -----------
slope=[];
for i=2:size(data_throughput,1),
    slope(i-1) = (data_throughput(i,2)-data_throughput(i-1,2))/(data_throughput(i,1)-data_throughput(i-1,1));
end

for i=2:size(slope,2),
    if slope(i) < (0.95*mean(slope(1:i)))
        max_pir = data_throughput(i, 1);
        max_throughput = data_throughput(i, 2);
        min_delay = data_delay(i, 2);
        break;
    end
end
